package com.sghd.fight.module.game.service.skill.effect;

import com.sghd.fight.module.game.config.SkillConfig;
import com.sghd.fight.module.game.core.Magic;
import com.sghd.fight.module.game.core.model.Unit;
import com.sghd.fight.module.game.service.room.IRoom;
import com.sghd.fight.module.game.service.skill.Context;
import com.sghd.pojo.fight.game.*;
import org.apache.commons.collections.MapUtils;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author frank
 * @date 2018-12-17 13:54
 * @desc 末日审判
 **/
@Component
public class ArmageddonEffect implements Effect {

    @Override
    public void execute(Context context, IRoom room, Unit owner, Unit target, Map<String, Object> ctx, SkillReport skillReport, TargetReport targetReport, SkillConfig config) {
        ChessType type = ChessType.valueOf(ctx.get(SOURCE).toString());
        int magic = target.getMagic(type);
        if (magic == Magic.magic_Max) {//最大魔法值
            int attack = MapUtils.getIntValue(ctx, MAX);
            target.getMagic().update(type, -magic);//魔法值清零
            int val = (int) (attack * getBet(owner, target));
            val = fixHp(owner, target, val, room, config);

            context.addValue(target, UnitValue.HP, -val);//造成血量
            targetReport.addValue(ValueItem.valueOf(UnitValue.HP, -val));
        } else {
            int count = MapUtils.getIntValue(ctx, COUNT);
            if (magic <= count) {
                count = magic;
            }
            target.getMagic().update(type, -count);//减少15
        }
    }

    @Override
    public EffectType getType() {
        return EffectType.SK_ARMAGEDDON;
    }
}
